#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <pthread.h>


int main() {


   int socket_fd = socket(AF_INET, SOCK_STREAM, 0);

   char *port = "9004";
   char *ip = "0.0.0.0";
   struct sockaddr_in sockaddr;
   sockaddr.sin_family = AF_INET;
   sockaddr.sin_port = htons(atoi(port));
   sockaddr.sin_addr.s_addr = inet_addr(ip);
   int reuse = 1;
   setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
   bind(socket_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
   listen(socket_fd, 10);

   int net_fd = accept(socket_fd, NULL, NULL);

   char buf[1024] = {0};
   recv(net_fd, buf, sizeof(buf), 0);
   printf("------------1------------ \n");
   printf("%s\n", buf);
   printf("------------1------------ \n");


   printf("------------2------------ \n");
   char *str1 = "HTTP/1.1 200 OK\r\n\r\n[\"test1\",\"test2\",\"test3\"]";
   send(net_fd, str1, strlen(str1), 0);
   printf("%s\n", str1);
   printf("------------2------------ \n");

   // 注意
   close(net_fd);

   while(1);

   close(socket_fd);
   return 0;

}

